<?php
class AdminController extends Zend_Controller_Action{
	public function init(){
		$this->view->baseUrl = $this->_request->getBaseUrl();
		Zend_Loader::loadclass('user');
		Zend_Loader::loadclass('role');
		Zend_Loader::loadclass('zendacl');
		$this->db=Zend_Registry::get('dbAdapter');
		}
		
	function indexAction()	
    { 	
		$this->view->title = 'plima管理系统';
		$this->render();
    } 
	
	function userAction(){
		$this->render();
		}
	
	function userdataAction(){
		$user=new user();
		$result=$user->fetchAll()->toArray();
		$total=sizeof($result);
		result($total,$result);
		exit;
		}
	
	function controlAction(){
		if($this->_request->isPost()){			
			$roleName	= $this->_request->getPost('role');
			$resource	= $this->_request->getPost('resource');
			$action		= $this->_request->getPost('action');
			$role_id	= $this->_request->getPost('role_id');
			$acl = new zendacl($roleName,$resource,$action);
			$strAcl=$acl->initAcl();			
			$role=new role();
			$data=array(
						"role_name"		=> $roleName,
						"role_acl"		=> $strAcl
						);
			if(!empty($role_id)){
				$role->update($data,'role_id='.$role_id);	
				}else{			
				$role->insert($data);
			}
			echo "<script>alert('提交成功')</script>";
			echo "<script>parent.Ext.getCmp('win_show').close()</script>";			
			exit;
			}
		}
	
	function controlprivateAction(){
		if($this->_request->isPost()){			
			$roleName	= $this->_request->getPost('role');
			$resource	= $this->_request->getPost('resource');
			$action		= $this->_request->getPost('action');
			$acl = new zendacl($roleName,$resource,$action);
			$strAcl=$acl->initAcl();			
			$role=new role();
			$data=array(
						"role_name"		=> $roleName,
						"role_acl"		=> $strAcl
						);
			$role->insert($data);
		}
	}
		
	function roledataAction(){
		$select=$this->db->select();
		$select->from('plm_role','*')
			   ->order('role_id DESC');
		$role=$this->db->fetchAll($select->__toString());	   
		//print_r($role);
		$size=sizeof($role);
		//result($size,$role);
		$results=json_encode($role);
		echo "{total:".$size.",results:".$results."}";
		exit;
		}
		
	function controlpageAction(){
		
		}
	
	function testAction(){
		$data=json_decode($_POST['data']);
		print_r($data);
		exit;
		}
		
}
?>